package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.FeeBill;
import com.egao.orderB.service.FeeBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/feeBill")
@RestController
@Api(value = "收款单",tags = {"收款单"})
public class ApiFeeBillController extends BaseController {
    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private FeeBillService feeBillService;

    /**
     * 收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:list')")
    @PostMapping("/list")
    @ApiOperation(value = "收款单列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "customerId:客户id\n" +
            "customerName:客户名称\n" +
            "stateS:收款状态 已收款,已实收\n" +
            "stateF:付款状态 已付款,已实付\n" +
            "date1  收款时间(charge_time)开始时间 比如2021-10-10 12:00:00" +
            "date2  收款时间(charge_time)结束时间 比如2021-10-10 14:00:00\n" +
            "返回的字段:\n" +
            "id:id\n" +
            "billIds:订单ids 以逗号分开:1,2,3,4\n" +
            "bankReceiptPic:水单图片,图片上传统一放到bill专用的上传接口\n" +
            "customerId:客户id\n" +
            "customerName:客户名称\n" +
            "remark:备注\n" +
            "stateS:收款状态 已收款,已实收\n" +
            "stateF:付款状态 已付款,已实付\n" +
            "chargeTime:收款时间\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "billList:订单列表\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, FeeBill feeBill, HttpServletRequest request)  throws Exception{
        return feeBillService.list(page, feeBill, getLoginUser());
    }

    /**
     * 收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:list')")
    @PostMapping("/listAll")
    @ApiOperation(value = "收款单列表",notes = "" +
            "",httpMethod = "POST")
    public JsonResult listAll(FeeBill feeBill, HttpServletRequest request)  throws Exception{
        return feeBillService.list(feeBill, getLoginUser());
    }



    /**
     * 添加收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:save')")
    @OperLog(value = "收款单", desc = "添加收款单", result = true)
    @PostMapping("/save")
    @ApiOperation(value = "添加收款单",notes = "\n" +
            "customerId:客户id 必填\n" +
            "customerName:客户名称 必填\n" +
            "billIds:订单ids 以逗号分开:1,2,3,4 必填\n" +
            "bankReceiptPic:水单图片,图片上传统一放到bill专用的上传接口 必填\n" +
            "stateS:收款状态 已收款,已实收\n" +
            "stateF:付款状态 已付款,已实付\n" +
            "chargeTime:收款时间\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    public JsonResult save(FeeBill feeBill, HttpServletRequest request) {
        return feeBillService.save(feeBill, getLoginUser());
    }


    /**
     * 修改收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:update')")
    @OperLog(value = "收款单", desc = "修改收款单", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "修改收款单",notes = "" +
            "id:id 必填\n" +
            "billIds:订单ids 以逗号分开:1,2,3,4 必填\n" +
            "bankReceiptPic:水单图片,图片上传统一放到bill专用的上传接口 必填\n" +
            "stateS:收款状态 已收款,已实收\n" +
            "stateF:付款状态 已付款,已实付\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    public JsonResult update(FeeBill feeBill, HttpServletRequest request) {
        try {
            return feeBillService.update(feeBill, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    /**
     * 修改收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:update')")
    @OperLog(value = "收款单", desc = "修改收款状态", result = true)
    @PostMapping("/updateStateS")
    @ApiOperation(value = "修改收款状态",notes = "" +
            "id:id 必填\n" +
            "stateS:收款状态 已收款,已实收 必填\n" +
            "",httpMethod = "POST")
    public JsonResult updateStateS(FeeBill feeBill, HttpServletRequest request) {
        try {
            return feeBillService.updateStateS(feeBill, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    /**
     * 修改收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:update')")
    @OperLog(value = "收款单", desc = "修改付款状态", result = true)
    @PostMapping("/updateStateF")
    @ApiOperation(value = "修改付款状态",notes = "" +
            "id:id 必填\n" +
            "stateF:付款状态 已付款,已实付 必填\n" +
            "",httpMethod = "POST")
    public JsonResult updateStateF(FeeBill feeBill, HttpServletRequest request) {
        try {
            return feeBillService.updateStateF(feeBill, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    /**
     * 删除收款单
     */
    @PreAuthorize("hasAuthority('orderB:feeBill:remove')")
    @OperLog(value = "收款单", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "删除收款单",notes = "id:id必填",httpMethod = "POST")
    public JsonResult remove(FeeBill feeBill, HttpServletRequest request) {
        return feeBillService.remove(feeBill, getLoginUser());
    }

}
